home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / tex-k / tex-k-archive.past / 1994.12.gz / 1994.12 / 000038_Dinh-Tuan.Pham@imag.fr_Wed Dec 7 20:09:51 1994.msg < prev    next >
Internet Message Format  |  1994-12-30  |  9KB

  1. Received: from imag.imag.fr by cs.umb.edu with SMTP id AA13129
  2.   (5.65c/IDA-1.4.4 for <tex-k@cs.umb.edu>); Wed, 7 Dec 1994 13:08:16 -0500
  3. Received: from puma.imag.fr by imag.imag.fr with SMTP id AA05109
  4.   (5.65c8/IDA-1.4.4 for <tex-k@cs.umb.edu>); Wed, 7 Dec 1994 19:08:14 +0100
  5. Received: by puma.imag.fr (5.0/SMI-SVR4)
  6.     id AA16013; Wed, 7 Dec 1994 19:09:51 --100
  7. Date: Wed, 7 Dec 1994 19:09:51 --100
  8. Message-Id: <9412071809.AA16013@puma.imag.fr>
  9. To: tex-k@cs.umb.edu
  10. Subject: xdvik and Selfile
  11. From: Dinh-Tuan.Pham@imag.fr
  12. Content-Length: 7694
  13.  
  14.     Hi,
  15.     I have made some modifications to the SelFile widget in xdvik,
  16. which cluld be of interest for inclusion in a future release. The
  17. purpose is implement a file filter so that the widget will display
  18. only *.dvi files (for ex.). The filter mask (*.dvi by default) can be
  19. changed by the user. Also, there is a switch to hide/show the "dot"
  20. files (file with name begining with .).
  21.     Here is the patch
  22.  
  23. --------------------- cut here ---------------------------
  24. *** xdvik/sfSelFile.c.orig    Tue Dec  6 16:03:04 1994
  25. --- xdvik/sfSelFile.c    Wed Dec  7 08:11:58 1994
  26. ***************
  27. *** 89,94 ****
  28. --- 89,100 ----
  29.       selFilePrompt,
  30.       selFileVScrolls[3];
  31.   
  32. + /* addition for file filter */
  33. + Widget    selFileLabel, selFileMask, selFileHide;
  34. + #define MASKWIDTH 10
  35. + char     fileMask[MASKWIDTH+2] = "*.dvi";
  36. + /* end addition */
  37.   Display *SFdisplay;
  38.   
  39.   Pixel SFfore, SFback;
  40. ***************
  41. *** 221,226 ****
  42. --- 227,332 ----
  43.       {"SelFileDismiss",    SFdismissAction},
  44.   };
  45.   
  46. + /* addition for file filter */
  47. + int    maskFile(mask, filename)
  48. + char    *mask, *filename;
  49. + /* return 1 if file is masked (mask does not match filename), 0 otherwise */
  50. + {
  51. + int     c, c1;
  52. +     while  (c = *mask++) {
  53. +       if (c == '*') {
  54. +         while (c1 = *mask++) {
  55. +           if (c1 != '*') {
  56. +         if (!(*filename)) return 1;
  57. +         if (c1 != '?') {
  58. +           while (filename = strchr(filename, c1)) {
  59. +             if (!maskFile(mask, ++filename)) return 0;
  60. +           }
  61. +           return 1;
  62. +         }
  63. +         else filename++;
  64. +           }
  65. +         }
  66. +         return 0;
  67. +       }
  68. +       if (c == '?') { if (!*filename) return 1; }
  69. +       else if (c != *filename) return 1;
  70. +       filename++;
  71. +     }
  72. +     return (*filename)? 1 : 0;
  73. + }
  74. + #include <sys/stat.h>
  75. + #if !defined(S_ISDIR) && defined(S_IFDIR)
  76. + #define    S_ISDIR(m)    (((m) & S_IFMT) == S_IFDIR)
  77. + #endif
  78. + int    hideFlag = 1;
  79. + int    showEntry(entryReal, entryShown, statBuf)
  80. + char    *entryReal, **entryShown;
  81. + struct    stat    *statBuf;
  82. + {
  83. +     if (!(S_ISDIR(statBuf->st_mode))) {
  84. +       if (hideFlag)
  85. +         if (entryReal[0] == '.') return 0;
  86. +       if (maskFile(fileMask, entryReal)) return 0;
  87. +     }
  88. +     entryReal[strlen(entryReal)] = SFstatChar(statBuf);
  89. +         return 1;
  90. + }
  91. + /* ARGSUSED */
  92. + void    maskChanged(w, client_data, event)
  93. + Widget        w;
  94. + XtPointer    client_data;
  95. + XKeyPressedEvent    *event;
  96. + {
  97. + char    buf[2];
  98. + register SFDir        *dir;
  99. + register SFEntry    *entry;
  100. + extern void SFupdatePath ();
  101. +     if ((XLookupString(event, buf, 2, NULL, NULL) == 1) &&
  102. +         ((*buf) == '\r')) {
  103. +       for (dir = &(SFdirs[SFdirEnd - 1]); dir >= SFdirs; dir--)
  104. +         *(dir->dir) = 0; /* force a re-read */
  105. +       SFupdatePath();
  106. +     }
  107. + }
  108. + /* ARGSUSED */
  109. + void    hideFiles(w, client_data, event)
  110. + Widget    w;
  111. + XtPointer    client_data;
  112. + XEvent    *event;
  113. + {
  114. + register SFDir        *dir;
  115. + register SFEntry    *entry;
  116. + extern void SFupdatePath ();
  117. +     hideFlag = 1 - hideFlag;
  118. +     if (hideFlag) {
  119. +       XtVaSetValues(w, XtNlabel, "hidden", NULL);
  120. +       for (dir = &(SFdirs[SFdirEnd - 1]); dir >= SFdirs; dir--) {
  121. +         if (!(dir->nEntries)) continue;
  122. +         dir->vOrigin = 0;
  123. +         for (entry = &(dir->entries[dir->nEntries - 1]);
  124. +          entry >= dir->entries; entry--)
  125. +           entry->statDone = 0;
  126. +         SFdrawLists(SF_DO_SCROLL);
  127. +       }
  128. +     } else {
  129. +       XtVaSetValues(w, XtNlabel, "shown", NULL);
  130. +       for (dir = &(SFdirs[SFdirEnd - 1]); dir >= SFdirs; dir--)
  131. +         *(dir->dir) = 0;    /* force a re-read */
  132. +       SFupdatePath();
  133. +     }
  134. + }
  135. + /* end addition */
  136.   static void
  137.   SFcreateWidgets(toplevel, prompt, ok, cancel)
  138.       Widget    toplevel;
  139. ***************
  140. *** 345,351 ****
  141.   
  142.       XtOverrideTranslations(selFileField,
  143.           XtParseTranslationTable(oneLineTextEditTranslations));
  144. !     XtSetKeyboardFocus(selFileForm, selFileField);
  145.   
  146.       i = 0;
  147.       XtSetArg(arglist[i], XtNorientation, XtorientHorizontal);    i++;
  148. --- 451,458 ----
  149.   
  150.       XtOverrideTranslations(selFileField,
  151.           XtParseTranslationTable(oneLineTextEditTranslations));
  152. ! /*    XtSetKeyboardFocus(selFileForm, selFileField);
  153. !     need focus for selFileMask wigget to set the filter */
  154.   
  155.       i = 0;
  156.       XtSetArg(arglist[i], XtNorientation, XtorientHorizontal);    i++;
  157. ***************
  158. *** 473,478 ****
  159. --- 580,650 ----
  160.       selFileCancel = XtCreateManagedWidget("selFileCancel",
  161.           commandWidgetClass, selFileForm, arglist, i);
  162.   
  163. + /* addition for file filter */
  164. +     selFileLabel = XtVaCreateManagedWidget("selFileLabel",
  165. +         labelWidgetClass, selFileForm,
  166. +         XtNfromVert, selFileLists[0],
  167. +         XtNvertDistance, 30,
  168. +         XtNfromHoriz, selFileCancel,
  169. +         XtNhorizDistance, 60,
  170. +         XtNlabel,  "File Mask:",
  171. +         XtNborderWidth, 0,
  172. +         XtNtop, XtChainTop,
  173. +         XtNbottom, XtChainTop,
  174. +         NULL);
  175. +     
  176. +     selFileMask = XtVaCreateManagedWidget("selFileMask",
  177. +         asciiTextWidgetClass, selFileForm,
  178. +         XtNwidth, MASKWIDTH*SFcharWidth,
  179. +         XtNfromVert, selFileLists[0],
  180. +         XtNvertDistance, 30,
  181. +         XtNfromHoriz, selFileLabel,
  182. +         XtNhorizDistance, 0,
  183. +         XtNtop, XtChainTop,
  184. +         XtNbottom, XtChainTop,
  185. +         XtNstring, fileMask,
  186. +         XtNlength, sizeof(fileMask),
  187. +         XtNeditType, XawtextEdit,
  188. +         XtNwrap, XawtextWrapNever,
  189. +         XtNuseStringInPlace, True,
  190. +         NULL);
  191. +     for (i = 0; i < 3; i++)
  192. +       XtSetKeyboardFocus(selFileLists[i], selFileField);
  193. +     XtOverrideTranslations(selFileMask,
  194. +         XtParseTranslationTable(oneLineTextEditTranslations));
  195. +     XtAddEventHandler(selFileMask, KeyPressMask, False,
  196. +         maskChanged, (XtPointer) NULL);
  197. +     selFileLabel = XtVaCreateManagedWidget("selFileLabel",
  198. +         labelWidgetClass, selFileForm,
  199. +         XtNfromVert, selFileLists[0],
  200. +         XtNvertDistance, 30,
  201. +         XtNfromHoriz, selFileMask,
  202. +         XtNhorizDistance, 40,
  203. +         XtNlabel,  "dot files",
  204. +         XtNborderWidth, 0,
  205. +         XtNtop, XtChainTop,
  206. +         XtNbottom, XtChainTop,
  207. +         NULL);
  208. +     selFileHide = XtVaCreateManagedWidget("selFileHide",
  209. +         commandWidgetClass, selFileForm,
  210. +         XtNfromVert, selFileLists[0],
  211. +         XtNvertDistance, 30,
  212. +         XtNfromHoriz, selFileLabel,
  213. +         XtNhorizDistance, 2,
  214. +         XtNlabel, "hidden",
  215. +         XtNborderWidth, 0,
  216. +         XtNtop, XtChainTop,
  217. +         XtNbottom, XtChainTop,
  218. +         XtNcursorName, "dot",
  219. +                NULL);
  220. +     XtAddCallback(selFileHide, XtNcallback, hideFiles, NULL);
  221. + /* end addition */
  222.       XtSetMappedWhenManaged(selFile, False);
  223.       XtRealizeWidget(selFile);
  224.   
  225. ***************
  226. *** 577,588 ****
  227.                  strlen(prompt) + 2);
  228.           strcpy(buf, failed);
  229.           strcat(buf, sys_errlist[errno]);
  230. !         strcat(buf, "\n");
  231.           strcat(buf, prompt);
  232.       } else {
  233.           buf = XtMalloc(strlen(failed) + strlen(prompt) + 2);
  234.           strcpy(buf, failed);
  235. !         strcat(buf, "\n");
  236.           strcat(buf, prompt);
  237.       }
  238.       XtSetArg(args[0], XtNlabel, buf);
  239. --- 749,762 ----
  240.                  strlen(prompt) + 2);
  241.           strcpy(buf, failed);
  242.           strcat(buf, sys_errlist[errno]);
  243. ! /*         strcat(buf, "\n"); */
  244. !         strcat(buf, " ");
  245.           strcat(buf, prompt);
  246.       } else {
  247.           buf = XtMalloc(strlen(failed) + strlen(prompt) + 2);
  248.           strcpy(buf, failed);
  249. ! /*        strcat(buf, "\n"); */
  250. !         strcat(buf, " ");
  251.           strcat(buf, prompt);
  252.       }
  253.       XtSetArg(args[0], XtNlabel, buf);
  254. ***************
  255. *** 726,732 ****
  256.           (void) strcpy(SFcurrentPath, SFstartDir);
  257.       }
  258.   
  259. !     SFfunc = show_entry;
  260.   
  261.       SFtextChanged();
  262.   
  263. --- 900,908 ----
  264.           (void) strcpy(SFcurrentPath, SFstartDir);
  265.       }
  266.   
  267. ! /*    SFfunc = show_entry;
  268. !     disabled in order to implement file filter */
  269. !     SFfunc = showEntry;
  270.   
  271.       SFtextChanged();
  272.   
  273. -------------- end of patch ----------
  274. -----------------------------------------------------------------------
  275. PHAM Dinh Tuan                         | e-mail: Dinh-Tuan.Pham@imag.fr
  276. Laboratoire de Modelisation et Calcul  | Tel: +33 76 51 44 23
  277. BP 53, 38041 Grenoble cedex 9 (France) | Fax: +33 76 63 12 63
  278. -----------------------------------------------------------------------